package com.ruoyi.platform.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.platform.domain.CouponTemplates;
import com.ruoyi.platform.service.ICouponTemplatesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 优惠券模板Controller
 * 
 * @author ruoyi
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/platform/cuopon_templates")
public class CouponTemplatesController extends BaseController
{
    @Autowired
    private ICouponTemplatesService couponTemplatesService;

    /**
     * 查询优惠券模板列表
     */
    @PreAuthorize("@ss.hasPermi('platform:cuopon_templates:list')")
    @GetMapping("/list")
    public TableDataInfo list(CouponTemplates couponTemplates)
    {
        startPage();
        List<CouponTemplates> list = couponTemplatesService.selectCouponTemplatesList(couponTemplates);
        return getDataTable(list);
    }

    /**
     * 导出优惠券模板列表
     */
    @PreAuthorize("@ss.hasPermi('platform:cuopon_templates:export')")
    @Log(title = "优惠券模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CouponTemplates couponTemplates)
    {
        List<CouponTemplates> list = couponTemplatesService.selectCouponTemplatesList(couponTemplates);
        ExcelUtil<CouponTemplates> util = new ExcelUtil<CouponTemplates>(CouponTemplates.class);
        util.exportExcel(response, list, "优惠券模板数据");
    }

    /**
     * 获取优惠券模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('platform:cuopon_templates:query')")
    @GetMapping(value = "/{couponId}")
    public AjaxResult getInfo(@PathVariable("couponId") String couponId)
    {
        return success(couponTemplatesService.selectCouponTemplatesByCouponId(couponId));
    }

    /**
     * 新增优惠券模板
     */
    @PreAuthorize("@ss.hasPermi('platform:cuopon_templates:add')")
    @Log(title = "优惠券模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CouponTemplates couponTemplates)
    {
        return toAjax(couponTemplatesService.insertCouponTemplates(couponTemplates));
    }

    /**
     * 修改优惠券模板
     */
    @PreAuthorize("@ss.hasPermi('platform:cuopon_templates:edit')")
    @Log(title = "优惠券模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CouponTemplates couponTemplates)
    {
        return toAjax(couponTemplatesService.updateCouponTemplates(couponTemplates));
    }

    /**
     * 删除优惠券模板
     */
    @PreAuthorize("@ss.hasPermi('platform:cuopon_templates:remove')")
    @Log(title = "优惠券模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{couponIds}")
    public AjaxResult remove(@PathVariable String[] couponIds)
    {
        return toAjax(couponTemplatesService.deleteCouponTemplatesByCouponIds(couponIds));
    }
}
